{% extends "base.html" %}
{% load navigation_tags %}
{% load display_tags %}
{% load i18n %}
{% load authorization_tags %}
{% block content %}
    {{ block.super }}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading tight">
                    <h3 class="has-filters">
                        Notification Webhook List
                        <div class="dropdown pull-right">
                            <button id="show-filters" name="show filter" aria-label="show filter" data-toggle="collapse" data-target="#the-filters" class="btn btn-primary toggle-filters"> <i class="fa-solid fa-filter"></i> <i class="caret"></i> </button>
                            {% if "dojo.add_notification_webhook"|has_configuration_permission:request %}
                            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" name="show filter" aria-label="show filter"
                                  data-toggle="dropdown" aria-expanded="true">
                              <span class="fa-solid fa-screwdriver-wrench"></span>
                              <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu"
                                aria-labelledby="dropdownMenu1">
                                    <li role="presentation">
                                        <a href="{% url 'add_notification_webhook' %}">
                                            <i class="fa-solid fa-plus"></i> Add Notification Webhook
                                        </a>
                                    </li>
                            </ul>
                            {% endif %}
                        </div>
                    </h3>
                </div>
                <!-- <div id="the-filters" class="is-filters panel-body collapse {% if ntl.form.has_changed %}in{% endif %}">
                    {% include "dojo/filter_snippet.html" with form=ntl.form %} TODO
                </div> -->
            </div>
            {% if nwhs %}

                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=nwhs page_size=True %}
                </div>

                <div class="panel panel-default table-responsive">
                    <table id="note_types"
                           class="tablesorter-bootstrap table table-condensed table-striped">
                        <thead>
                        <tr>
                            <th>{% dojo_sort request 'Notification Webhook Name' 'name' 'asc' %}</th>
                            <th>URL</th>
                            <th>Status</th>
                            <th>Note</th>
                            <th>Owner</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for nwh in nwhs %}
                            <tr>
                              <td><a>{{ nwh.name }}</a></td>
                              <td><a>{{ nwh.url }}</a></td>
                              <td><a>{{ nwh.get_status_display }}
                                {% if nwh.first_error or nwh.last_error %}
                                    <i class="fa-solid fa-circle-question has-popover" data-trigger="hover" data-content="First error: {{ nwh.first_error | display_date_with_secs }}, Last error: {{ nwh.last_error | display_date_with_secs }}" data-placement="right" data-container="body" data-original-title="" title=""></i>
                                {% endif %}    
                              </a></td>
                              <td><a>{{ nwh.note }}</a></td>
                              <td><a>{% if nwh.owner %}<a class="" href="{% url 'view_user' nwh.owner.id %}">{{ nwh.owner }}</a>{% else %}System Webhook{% endif %}</a></td>
                              {% if "dojo.edit_notification_webhook"|has_configuration_permission:request %}
                                <td>
                                    <div class="centered">
                                        <div class="btn-group" role="group">
                                            <a class="btn btn-sm btn-warning"
                                               href="{% url 'edit_notification_webhook' nwh.id %}">
                                                <i class="fa-solid fa-file"></i> Edit / activate / deactivate
                                            </a>
                                            <a class="btn btn-sm btn-danger"
                                               href="{% url 'delete_notification_webhook' nwh.id %}">
                                                <i class="fa-solid fa-trash"></i> Delete
                                            </a>
                                        </div>
                                    </div>
                                </td> 
                                {% endif %}
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=nwhs page_size=True %}
                </div>
            {% else %}
                <p class="text-center">No Notification Webook found.</p>
            {% endif %}
        </div>
    </div>
{% endblock %}
{% block postscript %}
    {{ block.super }}
    {% include "dojo/filter_js_snippet.html" %}
{% endblock %}
